﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Business.Models;
using System.Data;

namespace Business.DAO
{
    public class PhuHuynhDAO
    {
        private ISSContext db = new ISSContext();
        public List<PhuHuynh> GetAll()
        {
            return db.PhuHuynh.ToList();
        }

        public PhuHuynh Get(int id)
        {
            PhuHuynh PhuHuynh = db.PhuHuynh.Find(id);
            return PhuHuynh;
        }

        public int Create(PhuHuynh PhuHuynh)
        {
            try
            {
                db.PhuHuynh.Add(PhuHuynh);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Edit(PhuHuynh PhuHuynh)
        {
            try
            {
                db.Entry(PhuHuynh).State = EntityState.Modified;
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public int Delete(int id)
        {
            try
            {
                PhuHuynh PhuHuynh = db.PhuHuynh.Find(id);
                db.PhuHuynh.Remove(PhuHuynh);
                return db.SaveChanges();
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public List<PhuHuynh> GetByTruongHoc(TruongHoc TruongHoc)
        {
            var query = from phuhuynh in db.PhuHuynh where phuhuynh.TruongHoc == TruongHoc select phuhuynh;
            List<PhuHuynh> lstPhuHuynh = query.ToList<PhuHuynh>();
            return lstPhuHuynh;
        }

       
    }
}